import java.util.Stack;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 刘远望
 * Date: 2025-04-14
 * Time: 21:44
 */
//双向链表实现队列
public class MyQueue {
    static class ListNode{
        public int val;
        public ListNode prev;
        public ListNode next;

        public ListNode(int val) {
            this.val = val;
        }
    }
    public ListNode first;
    public ListNode last;
    public int useSize;

    public void offer(int val){
        ListNode node = new ListNode(val);
        if(isEmpty()) {
            first = last = node;
        }else{
            last.next = node;
            node.prev = last;
            last = last.next;
        }
        useSize++;
    }

    public int poll(){
        if(isEmpty()){
            return -1;
        }else {
            int val = first.val;
            first = first.next;
            if(first != null){
                first.prev = null;
            }
            useSize--;
            return val;
        }
    }

    public int peek(){
        if(isEmpty()){
            return -1;
        }else {
            int val = first.val;
            return val;
        }
    }

    public boolean isEmpty(){
        return useSize == 0;
    }
}
